package com.duke.shaking.more;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;

import com.duke.shaking.BaseActivity;
import com.duke.shaking.R;
import com.duke.shaking.ShakeApplication;
import com.duke.shaking.ShakeTabActivity;
import com.duke.shaking.ShakeTabEvent;
import com.duke.shaking.auth.LoginActivity;
import com.duke.shaking.utils.PrefUtils;

public class MoreActivity extends BaseActivity 
		implements ShakeTabEvent {

	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_more);
        
	}
	
	public void onActive(ShakeTabActivity tabs) {
		tabs.initTitle(0,
				0,
				0,
				0,
				R.string.more);
	}

	public void onBackBtn() {
		// TODO Auto-generated method stub
		
	}

	public void onLeftBtn() {
		// TODO Auto-generated method stub
		
	}

	public void onRightBtn() {
		// TODO Auto-generated method stub
		
	}
	
	public void onChangePassword(View v) {
		Intent i = new Intent(this, ChangePasswordActivity.class);
		startActivity(i);
	}

	public void logout() {
		if(me != null) {
			me.setAuthToken(null);
			me.setHasLogin(false);
		}
		PrefUtils prefUtils = PrefUtils.getInstance(this, getString(R.string.ownerPref));

		prefUtils.remove(getString(R.string.savedPassword));
		ShakeApplication.getShared().afterLogout();
		finish();
		go(LoginActivity.class);
	}
	
	public void onLogout(View v) {
		
		Builder builder = new Builder(this);
		builder.setMessage(R.string.alert_logout);
		builder.setPositiveButton(R.string._continue, 
			new OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					logout();
					dialog.dismiss();
				}
			});
		builder.setNegativeButton(R.string.cancel, new OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					dialog.dismiss();
				}
			});
		
		AlertDialog alert = builder.create();
		alert.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        alert.show();
		
	}
}
